<?php 
function getCategoryParents($catID){
	$parentCatList = get_category_parents($catID,false,',');
	if(is_string($parentCatList)) $parentCatListArray = split(",",$parentCatList); else $parentCatListArray=array();
	return $parentCatListArray;
}

function get_post_meta_all($post_id){
    global $wpdb;
    $data   =   array();
    $wpdb->query("
        SELECT `meta_key`, `meta_value`
        FROM $wpdb->postmeta
        WHERE `post_id` = $post_id
    ");
    foreach($wpdb->last_result as $k => $v){
        $data[$v->meta_key] =   $v->meta_value;
    };
    return $data;
}

function get_category_id($cat_name){
	$term = get_term_by('name', $cat_name, 'category');
	return $term->term_id;
}


?>
<?php get_header(); ?>

    <div class="main-content-inner global-width">
    
    	<aside class="one-third">
        	<?php get_sidebar(); ?>
        </aside>
       	
      	<section class="contents two-third">
        	         
	        	<?php while ( have_posts() ) : the_post(); setPostViews(get_the_ID()); ?> 
                	<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
					<?php if(has_post_thumbnail($post->ID )) {
                            $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); 
                            $image = $image[0];
                          }
                          else
                            $image="http://armchairweddingguru.co.uk/wp-content/uploads/2012/03/img.gif";
                    ?>
                    <a href="<?php the_permalink(); ?>"><img src="<?php echo $image;?>" alt="Image" class="float-left"></a>
                    <div class="half float-right">
	                    <p><?php the_content(); ?></p>
	                    <?php 
							$meta = get_post_meta_all($post -> ID); 
	
							$cats = array();
							foreach((get_the_category()) as $category) {
								$cats[$category->cat_ID] = getCategoryParents($category->cat_ID); 
								if(count($cats[$category->cat_ID])==4){			//////// found parent of country
									$country = $cats[$category->cat_ID][1];
									$city = $cats[$category->cat_ID][2];
								}
							} 
							
						?>
	                    <div><h3 class="half">Address:</h3> <?php echo $meta['address1'].($meta['address1']!=""?",":" ").$meta['address2'] ?>
                        <div class="clearfix"></div></div>
	                    <div><h3 class="half">Post Code:</h3> <?php echo $meta['postcode'] ?><div class="clearfix"></div></div>
	                    <div><h3 class="half">City/County:</h3> <?php echo $city ?><div class="clearfix"></div></div>
	                    <div><h3 class="half">Country:</h3><?php echo $country ?><div class="clearfix"></div></div>
	                    <div><h3 class="half">Phone:</h3> <?php echo $meta['phone'] ?><div class="clearfix"></div></div>
	                    <div><h3 class="half">Email:</h3> <?php echo $meta['email'] ?></a><div class="clearfix"></div></div>
	                    <div><h3 class="half">Website:</h3> <?php echo $meta['webSite'] ?><div class="clearfix"></div></div>
                    </div>

                    <?php if(array_key_exists(12, $cats)): ?>
<!--					<table class="full-width">
                        <tr>
                            <th width="320">Facility Name</th>
                            <th width="150">Availability</th>
                            <th width="100">Range</th>
                            <th width="100">Rate</th>
                        </tr>
                
                        <tr>
                            <td><h4 align="center">Room Options</h4></td>
                        </tr>
                        
                        <tr>
                            <td>Place of Ceremony:</td>
                            <td><?=$meta['placeOfCeremony']?></td>
                            <td><?=$meta['placeOfCeremonyRange']?></td>
                        	<td>&pound;<?=$meta['placeOfCeremonyRate']?></td>
                        </tr>

                        <tr>
                            <td>Day Reception:</td>
                            <td><?=$meta['dayReception']?></td>
                            <td><?=$meta['dayReceptionRange']?></td>
                        	<td>&pound;<?=$meta['dayReceptionRate']?></td>
                        </tr>

                        <tr>
                            <td>Evening Reception:</td>
                            <td><?=$meta['eveningReception']?></td>
                            <td><?=$meta['eveningReceptionRange']?></td>
                        	<td>&pound;<?=$meta['eveningReceptionRate']?></td>
                        </tr>

                        <tr>
                            <td>Accommodation:</td>
                            <td><?=$meta['accommodation']?></td>
                            <td><?=$meta['accommodationRange']?></td>
                        	<td>&pound;<?=$meta['accommodationRate']?></td>
                        </tr>
                        
                        <tr>
                            <td><h4 align="center">Wedding Breakfast</h4></td>
                        </tr>

                        <tr>
                            <td>Arrival Drinks Packages:</td>
                            <td><?=$meta['arrivalDrinks']?></td>
                            <td><?=$meta['arrivalDrinksRange']?></td>
                        	<td>&pound;<?=$meta['arrivalDrinksRate']?></td>
                        </tr>

                        <tr>
                            <td>Adult:</td>
                            <td><?=$meta['adultBreakfast']?></td>
                            <td><?=$meta['adultBreakfastRange']?></td>
                        	<td>&pound;<?=$meta['adultBreakfastRate']?></td>
                        </tr>

                        <tr>
                            <td>Child  (0-13):</td>
                            <td><?=$meta['child1Breakfast']?></td>
                            <td><?=$meta['child1BreakfastRange']?></td>
                        	<td>&pound;<?=$meta['child1BreakfastRate']?></td>
                        </tr>

                        <tr>
                            <td>Child  (14-17):</td>
                            <td><?=$meta['child2Breakfast']?></td>
                            <td><?=$meta['child2BreakfastRange']?></td>
                        	<td>&pound;<?=$meta['child2BreakfastRate']?></td>
                        </tr>

                        <tr>
                            <td>Toast Drink:</td>
                            <td><?=$meta['toastDrink']?></td>
                            <td><?=$meta['toastDrinkRange']?></td>
                        	<td>&pound;<?=$meta['toastDrinkRate']?></td>
                        </tr>

                        <tr>
                            <td><h4 align="center">Evening Buffet</h4></td>
                        </tr>

                        <tr>
                            <td>Adult:</td>
                            <td><?=$meta['adultBuffet']?></td>
                            <td><?=$meta['adultBuffetRange']?></td>
                        	<td>&pound;<?=$meta['adultBuffetRate']?></td>
                        </tr>

                        <tr>
                            <td>Child  (0-13):</td>
                            <td><?=$meta['child1Buffet']?></td>
                            <td><?=$meta['child1BuffetRange']?></td>
                        	<td>&pound;<?=$meta['child1BuffetRate']?></td>
                        </tr>

                        <tr>
                            <td>Child  (14-17):</td>
                            <td><?=$meta['child2Buffet']?></td>
                            <td><?=$meta['child2BuffetRange']?></td>
                        	<td>&pound;<?=$meta['child2BuffetRate']?></td>
                        </tr>

                        
                        <tr>
                            <td><h4 align="center">Discount Available</h4></td>
                        </tr>
                        
                        <tr>
                            <td>Discount:</td>
                            <td></td>
                            <td></td>
                        	<td><?=$meta['discount']?>%</td>
                        </tr>
                        
                        </table>
-->                  <?php endif; ?>
	            <?php endwhile; ?>
                            		                       
    	</section>   
    	     
    	<div class="clearfix"></div>
    </div>
       

<!-- Main Content Ends -->
</section>

<?php get_footer(); ?>
